<template>
  <div class="product-add pb50" v-loading="loading">
    <!--编辑特价优惠商品-->
     <el-form size="small" :model="form" ref="form" :rules="rules" label-width="100px">
       <div class="common-form">编辑特价优惠商品</div>
       <el-form-item label="商品名称" prop="product_name"><el-input v-model="form.product_name" readonly class="max-w460"></el-input></el-form-item>
      <el-form-item label="图片">
        <div>
          <img :src="form.product_image" class="mt10" width="120px;" />
        </div>
      </el-form-item>
      <el-form-item label="排序"><el-input type="number" v-model="form.sort" placeholder="请输入数字" class="max-w460"></el-input></el-form-item>
       <!--提交-->
       <div class="common-button-wrapper">
         <el-button size="small" type="info" @click="cancelFunc" :loading="loading">取消</el-button>
         <el-button size="small" type="primary" @click="onSubmit" :loading="loading">提交</el-button>
       </div>
     </el-form>
  </div>
</template>

<script>
import OnsaleproductApi from '@/api/onsaleproduct.js';
export default {
  components: {},
  data() {
    return {
      /*是否加载完成*/
      loading: true,
      /*是否上传图片*/
      isupload: false,
      /*富文本配置*/
      ueditor: {
        text: '',
        config: {
          initialFrameWidth: 400,
          initialFrameHeight: 500
        }
      },
      /*form表单数据*/
      form: {
        assemble_product_id:'',
        product_name:'',
        product_image:'',
        sort:1
      },
      /*专区分类*/
      category: [],
      /*验证规则*/
      rules: {
      }
    };
  },
  created() {

    this.getDetail();

  },

  methods: {

    /*上传*/
    openUpload() {
      this.isupload = true;
    },

    getDetail() {
      let self = this;
      // 取到路由带过来的参数
      const productId = self.$route.query.productId;
      OnsaleproductApi.detail({productId: productId},true).then(res => {
          self.form = res.data.detail;
          self.loading = false;
        })
        .catch(error => {});
    },

    /*修改文章*/
    onSubmit() {
      let self = this;
      let params = this.form;
      // 取到路由带过来的参数
      OnsaleproductApi.editProduct(params, true)
        .then(data => {
          self.$message({
            message: data.msg,
            type: 'success'
          });
          self.$router.push('/plus/onsale/index');
        })
        .catch(error => {});
    },

    /*取消添加，返回文章列表*/
    cancelFunc() {
      this.$router.push({
        path: '/plus/onsale/index'
      });
    }
  }
};
</script>

<style>
</style>
